package com.shuhe.metastore;

import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;

public class MqttClientV3 {

    public static void testConnect(String brokerUrl, String client_id, String username, String password) throws Exception {
        MqttClient client = new MqttClient(brokerUrl, client_id);
        MqttConnectOptions options = new MqttConnectOptions();
        options.setUserName(username);
        options.setPassword(password.toCharArray());
        options.setCleanSession(true);
        client.connect(options);
        boolean connected = client.isConnected();
        client.disconnect();
    }

    public static void main(String[] args) throws Exception {
        testConnect("tcp://localhost:1883", "client_1", "admin", "123456");
    }
}
